package text;

import javax.swing.text.AbstractDocument;
import javax.swing.text.ComponentView;
import javax.swing.text.Element;
import javax.swing.text.IconView;
import javax.swing.text.LabelView;
import javax.swing.text.StyleConstants;
import javax.swing.text.View;
import javax.swing.text.ViewFactory;

/**
 * The view factory class creates custom views for pagination root view
 * (SectionView class) and paragraph (PageableParagraphView class)
 * 
 * @author Stanislav Lapitsky
 * @version 1.0
 */
class PageableViewFactory implements ViewFactory {
	
	private final PageableEditorKit editorKit;

	public PageableViewFactory(PageableEditorKit editorKit) {
		this.editorKit = editorKit;
	}
	
	/**
	 * Creates view for specified element.
	 * 
	 * @param elem
	 *            Element parent element
	 * @return View created view instance.
	 */
	public View create(Element elem) {
		String kind = elem.getName();
		if (kind != null) {
			if (kind.equals(AbstractDocument.ContentElementName)) {
				return new LabelView(elem);
			} else if (kind.equals(AbstractDocument.ParagraphElementName)) {
				return new PageableParagraphView(editorKit, elem);
			} else if (kind.equals(AbstractDocument.SectionElementName)) {
				return new SectionView(editorKit, elem, View.Y_AXIS);
			} else if (kind.equals(StyleConstants.ComponentElementName)) {
				return new ComponentView(elem);
			} else if (kind.equals(StyleConstants.IconElementName)) {
				return new IconView(elem);
			}
		}
		// default to text display
		return new LabelView(elem);
	}

}